/*
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2022-12-23 14:16:02
 * @LastEditors: huangtianyang
 * @LastEditTime: 2023-06-07 15:29:11
 * @FilePath: \cxl-admin\src\views\system\protocol\previewDialog\index.ts
 */
import { reactive, ref } from 'vue'
import { channelEnum } from '../edit/index'
import { getProtocolInformationById } from '@/apis/system/protocol'
export class PreviewData {
    /**
     * 定义弹窗数据
     */
    dialog = reactive({
        visible: false,
        id: ''
    })

    /**
     * 协议内容
     */
    content = ref('')

    /**
     * 协议名称
     */
    name = ref('')

    /**
     * 协议渠道
     */
    channel = ref('')

    /**
     * 协议版本号
     */
    version = ref('')

    /**
     * 协议创建时间
     */
    time = ref('')

    /**
     * 通过协议id 获取协议内容
     * @param id
     */
    getProtocolById = async (id: string) => {
        getProtocolInformationById(id).then(res => {
            this.content.value = res.data.data.content
            this.name.value = res.data.data.name
            const arr: string[] = []
            res.data.data.type.split(',').forEach((channel: number) => {
                arr.push(channelEnum[channel])
            })
            this.channel.value = arr.join('、')
            this.version.value = res.data.data.version
            this.time.value = res.data.data.createTime
        })
    }
}
